<?php
/**
 * Created by PhpStorm.
 * User: zhao
 * Date: 2018/4/27
 * Time: 13:41
 */

function isAliOrWx()
{
    //判断是不是微信
    if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
        return "Weixin";
    }
    //判断是不是支付宝
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'AlipayClient') !== false) {
        return "Alipay";
    }
    //哪个都不是
    return false;
}

function receiptSign($str)
{

    $new_str = strrev($str);

    $sum1=0;
    $sum2=0;
    for($i=0;$i<strlen($new_str);$i++){

        if($i%2==0){
            $sum1 += substr($new_str,$i,1);
        }else{
            $sum2 += substr($new_str,$i,1);
        }
    }

    $sum3 = $sum1 * 3 + $sum2;

    $sum = $sum3;
    if ($sum3 % 10 != 0) {
        $sum += 10 - $sum3 % 10;
    }

    return $sum - $sum3;
}